﻿@page "/application"

@inject IChatApplicationService ChatApplicationService
@inject NavigationManager NavigationManager

<MCard>
    
    <MCardText Class="pa-6">
        <MRow NoGutters>
            <MCol Cols="12"
                  Sm="6"
                  Md="8">
                <MTextField @bind-Value="Search" Color="primary" Class="rounded-2" HideDetails="@("auto")" Flat Dense Solo BackgroundColor="fill-lighten-1" Placeholder="Search">
                    <PrependInnerContent>
                        <MIcon Size=16 Class="mr-2 neutral-lighten-1--text">mdi-magnify</MIcon>
                    </PrependInnerContent>
                </MTextField>
            </MCol>
            <MCol Cols="6"
                  Md="2">
                <MButton Right Color="primary" MinWidth=80 Height=32 Class="ml-6 rounded-pill" OnClick="OnSearch">
                    搜索
                </MButton>
            </MCol>
            <MCol Cols="6"
                  Md="2">
                <AddChatApplication OnSucceed="OnSearch" />
            </MCol>
        </MRow>
    </MCardText>
</MCard>

@if (Result?.Result == null || Result.Result.Count == 0)
{
    <p style="font-size: 20px;text-align: center;color: darkgray;">
        暂无数据
    </p>
}
else
{
    <MRow NoGutters Style="padding: 8px;">
        @foreach (var item in Result.Result)
        {
            <MCol key="@item.Id" Cols=3 Style="margin: 5px;user-select:none;">
                <MCard Outlined OnClick="()=>OpenChatApplication(item)">
                    <MCardTitle>
                        <span style="font-weight:bold;margin-left:8px;font-size:16px;">
                            @item.Name
                        </span>
                        <MSpacer></MSpacer>
                        <MMenu Left
                               Bottom>
                            <ActivatorContent>
                                <MButton Icon @attributes="@context.Attrs">
                                    <MIcon>mdi-dots-vertical</MIcon>
                                </MButton>
                            </ActivatorContent>
                            <ChildContent>
                                <MList>
                                    <MListItem OnClick="async () => await Remove(item.Id)">
                                        <MListItemTitle>删除</MListItemTitle>
                                    </MListItem>
                                </MList>
                            </ChildContent>
                        </MMenu>
                    </MCardTitle>
                    <MCardActions>
                        <MChip Class="ma-2"
                               Label>
                            @item.ChatModel
                        </MChip>
                        <MSpacer></MSpacer>

                    </MCardActions>
                </MCard>
            </MCol>
        }
    </MRow>
}

<MCardText>
    <div class="d-flex">
        <div class="mr-auto pt-3 text-btn neutral-lighten-1--text"> @((page - 1) * pageSize + 1) - @(page * pageSize) 当前页： @(page)</div>
        @if (Result?.Total > 0)
        {
            <MPagination @bind-Value="page" Color="primary" Circle Length=@((int)(Result?.Total??0))></MPagination>
        }
    </div>
</MCardText>